<template>
<div>
    <el-image style="width: 150px; height: 150px" :src="data.path" fit="contain"></el-image>
    <el-divider  content-position="left">商品名称： {{data.coName}}</el-divider>
    <span style="float:left; padding-left: 20px"></span>
    <el-form :model="data" ref="data" label-width="100px" class="demo-ruleForm">
        <el-form-item label="商品价格" >
                <el-input v-model="data.price"></el-input>
        </el-form-item>
        <el-form-item label="商品库存" >
            <el-row>
                <el-col :span="4"><el-button type="info" @click="doCalculate(-10)">- 10</el-button></el-col>
                <el-col :span="4"><el-button type="info" @click="doCalculate(-1)">- 1</el-button></el-col>
                <el-col :span="8"><el-input v-model="data.amount"></el-input></el-col>
                <el-col :span="4"><el-button type="info" @click="doCalculate(1)">+ 1</el-button></el-col>
                <el-col :span="4"><el-button type="info" @click="doCalculate(10)">+ 10</el-button></el-col>
            </el-row>
        </el-form-item>
    </el-form>
    <el-row style="margin-top: 10px">
        <div style="float: right">
            <el-button type="primary" @click="doSureFunc">确认</el-button>
            <el-button @click="doCancelFunc">取消</el-button>
        </div>
    </el-row>
</div>
</template>

<script>
    export default {
        name: "EditCommodity",
        props:['data', 'EditWindowVisible','subsyetmChooseValue'],
        data(){
          return {
            changeValue: 0,
          }
        },
        methods:{
            // 按钮对应的确认按钮
            doSureFunc(){
                let form = new FormData();
                let win = this;
                form.append("server_code", this.subsyetmChooseValue);
                form.append("co_Id", this.data.coId);
                form.append("price", this.data.price);
                form.append("stock", this.changeValue);
                this.$http.post("/api/stock/update", form).then(function (response) {
                   if(response){
                        win.$message.success("修改成功");
                   } else {
                       win.$message.error("修改失败");
                   }
                });
                this.$emit('watchingEditCloseVisble',false);
            },
            // 按钮对应的取消按钮
            doCancelFunc(){
                this.changeValue = 0;
                this.$emit('watchingEditCloseVisble',false);
            },
            doCalculate(num){
                if(this.data.amount + num >= 0){
                    this.changeValue += num;
                    this.data.amount += num;
                } else {
                    this.data.amount = 0;
                }

            }
        }
    }
</script>

<style scoped>

</style>
